<template>
  <div class="HuikuiInfo el-card is-always-shadow el-card__body">
    <el-dialog
      title="回馈预览"
      :visible.sync="dialogVisible"
      @close="closed"
      width="950px">
      <avue-crud
        ref="crudTwo"
        :option="optionTableOne"
        :data="listTableOne">
        <template slot="menuLeft">
          TVM单台设备票款差异信息回馈
        </template>
        <!-- <template slot-scope="scope" slot="replyDiffMoney">
          <el-input :disabled="showType==2" v-model="scope.row.replyDiffMoney"/>
        </template> -->
        <template slot-scope="scope" slot="replyRechargeMoney">
          <el-input :disabled="showType==2" v-model="scope.row.replyRechargeMoney"/>
        </template>
        <template slot-scope="scope" slot="replySaleMoney">
          <el-input :disabled="showType==2" v-model="scope.row.replySaleMoney"/>
        </template>
        <template slot-scope="scope" slot="replyErrorReturnMoney">
          <el-input :disabled="showType==2" v-model="scope.row.replyErrorReturnMoney"/>
        </template>
      </avue-crud><br/><br/><br/>
      <avue-form :disabled="isReload" :option="option" v-model="formData" @submit="handleSubmit">
        <template  slot="replyReason" slot-scope="scope">
          <el-select :disabled="showType==2" v-model="replyReason" placeholder="请选择" style="width: 150px">
            <el-option
              v-for="(item,index) in replyReasonList"
              :key="index"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </template>
        <template slot-scope="scope" slot="menuForm" >
          <el-button v-if="showType==1" type="primary" @click="handleSubmit" >保存</el-button>
          <el-button @click="closed" >返回</el-button>
        </template>
      </avue-form>
    </el-dialog>
  </div>
</template>


<script>
  import {getForm, postForm} from '@/api/gen/gen'
  import {fenExYuangettoFixed,getSysDictItemListToDict,getQianxiangType,getLineName,getStationName} from "../../../../../../api/subwayRat/commonCheck";
  import {updateSwAuTvmSingleAssist} from "../../../../../../api/stationTiecketManager/shuJuXieChaGuanLi/TVM/XT/DTSB/TVMDanTaiSheBeiCY";
  export default {
    components:{
    },
    data() {
      return {
        replyReason :'',
        // replySaleMoney:0,
        // replyRechargeMoney:0,
        // replyErrorReturnMoney:0,
        optionTableOne:{},
        listTableOne:[],
        option:{},
        showType : 0,
        isReload:true,
        dialogVisible:true,
        formData:{},
        replyReasonList:[]
      }
    },
    created() {
      this.getOption();
      getSysDictItemListToDict({"type":"REPLY_REASON"}).then((response)=>{
        this.replyReasonList = response.data.data;
      });
    },
    methods: {
      async handleSubmit(){
        if(''==this.replyReason){
          this.$message.warning("请选择回馈原因后提交！");
          return
        }
        let p = {
          id:this.formData.id,
          //replyDiffMoney:this.listTableOne[0].replyDiffMoney*100,
          replyRechargeMoney:this.listTableOne[0].replyRechargeMoney*100,
          replySaleMoney:this.listTableOne[0].replySaleMoney*100,
          replyErrorReturnMoney:this.listTableOne[0].replyErrorReturnMoney*100,
          replyTotal:this.listTableOne[0].replyTotal*100,
          replyReason:this.replyReason,
          replyContent:this.formData.replyContent
        };
        await updateSwAuTvmSingleAssist(p).then((response)=>{
        });
        this.$message.success("提交成功");
        this.$parent.getList();
        this.closed();
      },
      recallShow(row){
        Object.assign(this.formData,row);
        //row.replyDiffMoney = (row.replyDiffMoney/100).toFixed(2);
        this.listTableOne.push(row);
        row.replyRechargeMoney = (row.replyRechargeMoney/100).toFixed(2);
        row.replySaleMoney = (row.replySaleMoney/100).toFixed(2);
        row.replyErrorReturnMoney = (row.replyErrorReturnMoney/100).toFixed(2);
        this.replyReason = row.replyReason;
        if(2==this.showType){
          this.option.group[0].column[1].disabled = true;
        }
      },
      closed(){
        for (var item of this.listTableOne) {
          item.replyRechargeMoney = item.replyRechargeMoney*100;
          item.replySaleMoney = item.replySaleMoney*100;
          item.replyErrorReturnMoney = item.replyErrorReturnMoney*100;
        }
        this.dialogVisible=false;
        this.$parent.isShowDia=false;
      },
      getOption(){
        this.showType = this.$parent.showType;
        if(1 == this.$parent.showType) {
          this.isReload = false;
        }
        this.optionTableOne = {
          border: false,
          index: false,
          indexLabel: '序号',
          stripe: false,
          menuAlign: 'center',
          menu: false,
          viewBtn: false,
          editBtn: false,
          emptyBtn:false,
          delBtn: false,
          align: 'center',
          addBtn: false,
          column: [{
            fixed: true,
            label: '主键',
            prop: 'id',
            span: 24,
            type: 'input',
            hide: true
          }, {
            hide: false,
            label: '线路',
            prop: 'lineCode',
            type: 'select',
            filterable : true,
            search: false,
            formatter: function(row, value , label, column){
              return getLineName(value);
            },
            display: true // 动态显隐控制不能删除
          }, {
            hide: false,
            label: '站点',
            prop: 'stationCode',
            type: 'select',
            filterable : true,
            search: false,formatter: function(row, value , label, column){
              return getStationName(row.lineCode,value);
            },
            display: true// 动态显隐控制不能删除
          },
          // {
          //   hide: false,
          //   label: '线路名称',
          //   prop: 'lineCode',
          //   type: 'select',
          //   search: false,
          //   filterable : true,
          //   cascaderItem: ["stationCode"],
          //   props: {
          //     label: 'name',
          //     value: 'code'
          //   },
          //   dicUrl: "/check/check/getLineLists?userCode="+ this.$store.getters.userInfo.userCode,
          //   display: true // 动态显隐控制不能删除
          // }, {
          //   hide: false,
          //   label: '站点名称',
          //   prop: 'stationCode',
          //   type: 'select',
          //   filterable : true,
          //   search: false,
          //   dicFlag: false,
          //   cascaderItem: ["tvmOrder"],
          //   props: {
          //     label: 'name',
          //     value: 'code'
          //   },
          //   dicUrl: "/check/check/getStationLists?userCode="+ this.$store.getters.userInfo.userCode + "&lineCode={{key}}",
          //   display: true// 动态显隐控制不能删除
          // }, 
          {
            hide: false,
            label: 'TVM编号',
            prop: 'tvmCode',
            type: 'select',
            search: false,
            filterable : true,
            dicFlag: false,
            props: {
              label: 'tvmCode',
              value: 'tvmCode'
            },
            dicUrl: "/check/check/getSwPmTvmCodeList?stationCode={{key}}"
          }, {
            label: '收入日期',
            prop: 'incomeTime',
            type: 'datetime',
            format: 'yyyy-MM-dd',
            valueFormat: 'yyyy-MM-dd',
            search: false,
            hide: false,
            width: 120,
          }, {
            label: 'SC售票',
            prop: "saleAmount",
            hide: true,
            formatter:function (row,value , label, column) {
              return fenExYuangettoFixed(row,'saleAmount');
            },
          },  {
            label: 'SC充值',
            prop: "depositAmount",
            hide: true,
            formatter:function (row,value , label, column) {
              return fenExYuangettoFixed(row,'depositAmount');
            },
          },  {
            width:120,
            label: 'SC故障退款',
            prop: "errorRefundAmount",
            hide: true,
            formatter:function (row,value , label, column) {
              return fenExYuangettoFixed(row,'errorRefundAmount');
            },
          },  {
            width:120,
            label: '系统金额',
            prop: "tvmBillOrderMoney",
            formatter:function (row,value , label, column) {
              return fenExYuangettoFixed(row,'tvmBillOrderMoney');
            },
          }, {
            label: '实点金额',
            prop: "actualMoney",
            formatter:function (row,value , label, column) {
              return fenExYuangettoFixed(row,'actualMoney');
            },
          }, {
            width:120,
            label: '差异金额',
            prop: 'diffMoney',
            formatter:function (row,value , label, column) {
              return fenExYuangettoFixed(row,'diffMoney');
            },
            search: false,
            hide: false,
          },
          //  {
          //   label: '回馈差异金额',
          //   prop: 'replyDiffMoney',
          //   formatter:function (row,value , label, column) {
          //     return fenExYuangettoFixed(row,'replyDiffMoney');
          //   },
          //   search: false,
          //   slot:true,
          //   hide: false,
          // }, 
           {
             width:120,
            label: '协查售卖金额',
            prop: 'replySaleMoney',
            search: false,
            slot:true,
            hide: false,
          },
          {
            width:120,
            label: '协查充值金额',
            prop: 'replyRechargeMoney',
            search: false,
            slot:true,
            hide: false,
          }, {
            width:160,
            label: '协查故障退款金额',
            prop: 'replyErrorReturnMoney',
            search: false,
            slot:true,
            hide: false,
          }, {
            label: '合计',
            prop: 'replyTotal',
            formatter:function (row,value , label, column) {
              const replyRechargeMoney = row.replyRechargeMoney*100;
              const replySaleMoney = row.replySaleMoney*100;
              const replyErrorReturnMoney = row.replyErrorReturnMoney*100;
              let sum = 0;
              if (!isNaN(replyRechargeMoney)) {
                sum += replyRechargeMoney;
              }
              if (!isNaN(replySaleMoney)) {
                sum += replySaleMoney;
              }
              if (!isNaN(replyErrorReturnMoney)) {
                sum += replyErrorReturnMoney;
              }
              row.replyTotal = sum;
              return fenExYuangettoFixed(row,'replyTotal');
            }
          }]
        };
        this.option={
          submitBtn:false,
          emptyBtn:false,
          labelWidth:"40%",
          group:[{
              icon:'',
              label: '',
              // collapse:false,
              prop: 'group',
              column: [{
                label: '机电专业回馈差异原因',
                prop: 'replyReason',
                formslot : true,
              },{
                label: '机电专业差异详情',
                prop: 'replyContent',
                type:'textarea',
                disabled:this.showType==2
              }]
            }]
        }
      }
    },
    mounted() {
    }
  }
</script>
